package com.day02.star;

import javax.swing.*;
import java.awt.*;
import java.util.Random;

/**
 * 画一个月亮
 */
public class CircleMain {
    public static void main(String[] args) {
        JFrame jFrame = new JFrame();
        CirclePanel cp = new CirclePanel() ;
        jFrame.add(cp);
        jFrame.setBackground(Color.BLACK);
        jFrame.setBounds(240,120,800,600);
        jFrame.setVisible(true);
        jFrame.setDefaultCloseOperation(3);
    }
}

class CirclePanel extends JPanel{

    Random ran ;
    int xs [] ;
    int ys [] ;
    public CirclePanel (){
        ran = new Random();
        xs = new int[300];
        ys = new int[300];

        for (int i = 0; i < xs.length; i++) {
            xs[i] = ran.nextInt(800);
            ys[i] = ran.nextInt(600);
        }
    }
    @Override
    public void paint(Graphics g) {
        // 循环中,不需要改变的变量, 都移到循环外。
        Font font = new Font("微软雅黑",1 , 20);
        // 画星星
        for (int i = 0; i < 300; i++) {
            Color color= new Color(ran.nextInt(256),ran.nextInt(256),ran.nextInt(256));
            g.setColor(color);
            g.setFont(font);
            // 星星的位置是随机的还是固定的 ?
            g.drawString("*",xs[i],ys[i]);
        }
        g.setColor(Color.YELLOW);   // 设置画笔颜色为黄色
        g.fillOval(50,50, 100,100);
        g.setColor(Color.BLACK);    // 设置画笔颜色为黑色
        g.fillOval(70,70, 100,100);
    }
}
